<include file="Public:header" />
<style type="text/css">
.call-records {
}
.current-bg {
	background-color: #fbffe4
}
</style>
<div class="subnav">
  <div class="explain-col" style="position: relative; ">
    <form name="searchForm" id="searchForm" method="GET" action="" onsubmit="return checkForm()">
      搜索：
      <input type="text" name="keyword" id="keyword" size="30"  value="{$Think.get.keyword|getChineseGetValue}" class="input-text" onClick="if(this.value=='请输入联系人姓名或电话号码')this.value=''"  onblur="if(this.value=='')this.value='请输入联系人姓名或电话号码'" style="height:20px; width:180px; color:#999" />
      <select name="groupId" id="groupId" >
        <option value="0">所有分组</option>
        <volist name="groupList" id="vo"> <option value="{$vo.id}" 
          
          <eq name="Think.get.groupId" value="$vo.id"> selected="selected"</eq>
          
          />{$vo.name}
          
          </option>
        </volist>
      </select>
      <eq name="_SESSION['roleId']" value="1">
        <select name="userId" id="userId" >
          <option value="0" selected="selected">请选择用户</option>
          <volist name="userList" id="vo"> <option value="{$vo.id}" 
            
            <eq name="Think.get.userId" value="$vo.id"> selected="selected"</eq>
            
             />{$vo.username}
            
            </option>
          </volist>
        </select>
      </eq>
      查看模式{$Think.cookie.checkedModeCookie}
      <input name="viewMode" type="radio" value="1" checked="checked">窗口
      <input name="viewMode" type="radio" value="2">响应
      <input name="checkedMode" type="hidden" value="1">
      <input type="button" value=" 搜索 " class="button" id="searchButton" />
    </form>
    <div class="content-menu" style="position: absolute; right: 30px;top: 5px;"> <a href="javascript:openWinBox('__URL__/add','添加电话记录',850);" class="add fb"><em>添加电话记录</em></a> </div>
  </div>
</div>
<!--subnav-->
<div class="pad-lr-10">
  <form name="myform" id="myform" action="" method="GET">
    <div class="table-list">
      <table width="100%" cellspacing="0" style="min-width:900px;">
        <thead>
          <tr>
            <th align="center" width="40" >选择</th>
            <th align="left" width="80"  >所属分组</th>
            <th align="left" width="40">联系人</th>
            <th align="center" >联系电话</th>
            <th align="center" width="30">性别</th>
            <th align="left" width="80">区域</th>
            <th align="center" width="40">电话数</th>
            <th align="center" >创建人</th>
            <th align="center" width="120">更新时间</th>
            <th align="center" width="220">操作</th>
          </tr>
        </thead>
        <tbody  id="list">
          <volist name="list" id="vo">
            <tr id="list-{$vo.id}" value="{$vo.id}">
              <td align="center"><input type="checkbox" name="idArr[]" value="{$vo.id}"></td>
              <td align="left" >{$vo.groupName}</td>
              <td align="left">{$vo.name}</td>
              <td align="center">{$vo.phone}</td>
              <td align="center">{$vo.sexName}</td>
              <td align="left">{$vo.provinceName}{$vo.cityName}{$vo.areaName}</td>
              <td align="center">{$vo.count}</td>
              <td align="center">{$vo.creater}</td>
              <td align="center">{$vo.update_time|date='Y-m-d H:i:s',###}</td>
              <td align="center" class="detail">
              <a href="javascript:void(0)" onclick="selectMode({$vo.id});" >【查看】</a> 
              <a href="javascript:openWinBox('__URL__/add/id/{$vo.id}','修改电话信息',860,250)" >【修改】</a> 
              <a href="javascript:openWinBox('__URL__/addContent/id/{$vo.id}','追加电话内容',850)" >【追加电话内容】</a>
              </td>
            </tr>
          </volist>
        </tbody>
      </table>
    </div>
    <div class="btn" style="min-width:830px;" >
      <div id="pages">{$page}</div>
      <input name="submit" id="checkall" type="button" class="button" value="全选/反选">
      <input name="submit" type="button" class="button" value="删除所选"  onclick="return deleteConfirm();">
      <input name="submit" type="button" class="button" value="导出客户资料"  onclick="return exportExcel();">
    </div>
  </form>
</div>
</body>
</html>

<script type="text/javascript">
$(function(){
	var keyword = $('input[name=keyword]').val();
	if( keyword=='' ){
		$('input[name=keyword]').val('请输入联系人姓名或电话号码');
	}
	
	$('#myform').ajaxForm({
		beforeSubmit:  checkForm,
		success:       complete,
		dataType: 'json'
	});
	function checkForm(){
		var len = $("input[name='spaceid[]']:checked").length;
		if(len < 1){
			msg('请先选择删除项！','warning',3);
			return false;
		}
	}
	var origin = $.artDialog.open.origin;
	function complete(data){
		msg(data.info,data.data);
		if(data.status) setTimeout(function(){origin.location.reload();},1500);
	}
	
	//全反选
	$("#checkall").click(function(){
		$("input[name=idArr[]]").each(function(){
			if(this.checked == false)
				this.checked = true;
			else
				  this.checked = false;
		});
	});
	
	$('#groupId').change(function(){
		$("#searchForm").attr('action','__URL__/index');
		$("#searchForm").submit();
	})
	
	$('#userId').change(function(){
		$("#searchForm").attr('action','__URL__/index');
		$("#searchForm").submit();
	})
	
	$('input[name=keyword]').change(function(){
		$("#searchForm").attr('action','__URL__/index');
		$("#searchForm").submit();
	})
	
	$("#searchButton").click(function(){
		$("#searchForm").attr('action','__URL__/index');
		$("#searchForm").submit();
	})
	
	$("input[name='viewMode']").change(function(){
		var mode = $(this).val();
		$("input[name='checkedMode']").val(mode);
	})
	
})
	

function checkedId(){
	var id = new Array();
	var i = 0;
	$("input[name='idArr[]']").each(function() { //由于复选框一般选中的是多个,所以可以循环输出 
		if(this.checked == true){
			id[i] = $(this).val(); 
			i++;
			$('#list-'+$(this).val()).remove();
		}
	});
	return id;
}

function deleteConfirm(){
	window.top.art.dialog({
		content: '确定删除所选数据？',
		ok: function () {
			del();
			return true;
		},
		cancelVal: '取消',
		cancel: true
	});
}

function del(){
	var idArr = Array();
	var i = 0;
	var id;
	$("input[name='idArr[]']").each(function(){
		if(this.checked == true){
			idArr[i] = $(this).val();
			i++;
		}
	});
	jQuery.post('__URL__/del',encodeURI('id='+idArr),success,'json');
	function success(data){
		if(data.status==1){
			window.top.art.dialog({id:'TNCICC',content: data.info,time: 2,icon:'succeed'});
			setTimeout(function(){window.location.reload();closeWin(1500);},2000);
		}else{
			window.top.art.dialog({id:'TNCICC',content: data.info,time: 2,icon:'warning'});
		}
		
	}
}

function checkForm(){
	var keyword = $("input[name='keyword']").val();
	keyword = encodeURI(keyword).replace(/%/g,'.s.');
	$("input[name='keyword']").val(keyword);
	return true;
}

function exportExcel(){
	$("#searchForm").attr('action','__URL__/exportExcel');
	$("#searchForm").submit();
	return false;
}


function selectMode(clientId){
	var checkedMode = $("input[name='checkedMode']").val();
	if(checkedMode==1){
		openWinBox('__URL__/detail/id/'+clientId,'查看详细信息');
	}else{
		loadCallRecord(clientId);
	}
}

function loadCallRecord(id){
		if($('#content-'+id).attr('id')!=undefined){
			$('.call-records').hide();
			$('.current-bg').removeClass('current-bg');
			$('#content-'+id).show();
			
			$('#content-'+id).addClass('current-bg');
			$('#list-'+id).addClass('current-bg');
		}else{
			getCallRecordList(id);
		}
		return true;
}

function getCallRecordList(id){
	$.ajax({ 
			type:'GET', 
			url:"__URL__/getCallRecord", 
			dataType:'text', 
			data:encodeURI('id='+id),
			beforeSend:function(){
				$('#list-'+id).after('<tr class="jiazai"><td align="center" colspan="10" style="color:#F00" >正在加载。。。</td></tr>');
				$('.call-records').hide();
				$('.current-bg').removeClass('current-bg');
			},
			success:function(data){
				var data = eval('('+data+')');
				$('#list-'+id).after(data.data);
		  		$('#list-'+id).addClass('current-bg');
				$('#content-'+id).addClass('current-bg');
			},
			complete: function(XMLHttpRequest, textStatus){
				$('.jiazai').remove();
			},
			error: function(){} ,
		});
		return true;
}
</script>